<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>set与get练习</title>
    <script src="../../js/vue.js"></script>
  </head>
  <body>
    <div id="app">
      <h2>{{this.text_1+" "+this.text_2}}</h2>
      <h2>{{getText()}}</h2>
      <h2>{{getTexts}}</h2>
      <button v-on:click="setText">切换</button>
    </div>
    <script>
      var v_app = new Vue({
        el: "#app",
        data: {
          text_1: "hello",
          text_2: "apple",
          text: "hi star",
        },
        methods: {
          getText() {
            console.log("methods方法执行");
            return this.text_1 + " " + this.text_2;
          },
          setText() {
            console.log("getTexts改变");
            this.getTexts = this.text;
          },
        },
        computed: {
          getTexts: {
            get() {
              console.log("getTexts-get方法执行");
              return this.text_1 + " " + this.text_2;
            },
            set(texts) {
              console.log("getTexts-set方法执行");
              arr = texts.split(" ");
              this.text_1 = arr[0];
              this.text_2 = arr[1];
            },
          },
        },
      });
    </script>
  </body>
</html>
